#!/bin/bash

# createAll.sh
# created 2021 February 28

# This file automatically generates all of the figures and tables in  
# "Response Options and the Measurement of Political Knowledge."



# CREATE DIRECTORIES FOR OUTPUT FILES
if [ -d "batchOutput" ]
then
  echo "The batchOutput directory already exists."
else 
  `mkdir batchOutput`
fi


if [ -d "float_output" ]
then
  echo "The float_output directory already exists."
else 
  `mkdir float_output`
fi



# **************************************************************************
# MAKE TABLES AND FIGURES ####
# **************************************************************************

  # ARGUMENTS FOR FIGURE 1: SHOW_GUESSING_CORRECTED_PANEL
  R CMD BATCH "--no-save --args FALSE" "R/float_code/Figure_1.R" "batch_output/out_Figure_1.txt"

  # CREATE TABLES 1 AND A14 IN "Table_1.tex"
  R CMD BATCH "--no-save" "R/float_code/Table_1.R" "batch_output/out_Tables_1_and_A14.txt"
    
  # ARGUMENTS FOR TABLE 2: MODELS_WITH_CONTROLS, ONLY_SUBJECTS_WHO_ANSWERED_CONTROL_QUESTIONS, ONLY_SUBJECTS_WHO_HAVE_WEIGHTS, USE_WEIGHTS, CREATE_SCREENER_TABLES
  R CMD BATCH "--no-save --args FALSE TRUE TRUE TRUE FALSE" "R/float_code/Table_2.R" "batch_output/out_Tables_2_and_A13.txt"


  
  # **********************************************************************
  # * APPENDIX 
  # **********************************************************************  

  # CREATE FIGURE A1
  R CMD BATCH "--no-save" "R/float_code/Figure_A1.R" "batch_output/out_Figure_A1.txt"

  # ARGUMENTS FOR FIGURE A2: SHOW_GUESSING_CORRECTED_PANEL
  R CMD BATCH "--no-save --args TRUE" "R/float_code/Figure_1.R" "batch_output/out_Figure_A2.txt"

  # CREATE TABLES A1 AND A2
  R CMD BATCH "--no-save" "R/float_code/Table_A1.R" "batch_output/out_Tables_A1-A2.txt"

  # ARGUMENTS FOR TABLE A3: MODELS_WITH_CONTROLS, ONLY_SUBJECTS_WHO_ANSWERED_CONTROL_QUESTIONS, ONLY_SUBJECTS_WHO_HAVE_WEIGHTS, USE_WEIGHTS, CREATE_SCREENER_TABLES
  R CMD BATCH "--no-save --args FALSE TRUE TRUE FALSE FALSE" "R/float_code/Table_2.R" "batch_output/out_Table_A3.txt"
  
  # ARGUMENTS FOR TABLE A4: MODELS_WITH_CONTROLS, ONLY_SUBJECTS_WHO_ANSWERED_CONTROL_QUESTIONS, ONLY_SUBJECTS_WHO_HAVE_WEIGHTS, USE_WEIGHTS, CREATE_SCREENER_TABLES
  R CMD BATCH "--no-save --args FALSE FALSE FALSE FALSE FALSE" "R/float_code/Table_2.R" "batch_output/out_Table_A4.txt"
  
  # CREATE TABLE A5
  R CMD BATCH "--no-save --args TRUE" "R/float_code/Table_A5.R" "batch_output/out_Table_A5.txt"
  
  # ARGUMENTS FOR TABLES A6-A9: MODELS_WITH_CONTROLS, ONLY_SUBJECTS_WHO_ANSWERED_CONTROL_QUESTIONS, ONLY_SUBJECTS_WHO_HAVE_WEIGHTS, USE_WEIGHTS, CREATE_SCREENER_TABLES
  R CMD BATCH "--no-save --args FALSE TRUE TRUE TRUE TRUE" "R/float_code/Table_2.R" "batch_output/out_Tables_A6-A9.txt"

  # CREATE TABLE A10
  R CMD BATCH "--no-save --args TRUE" "R/float_code/Table_A10.R" "batch_output/out_Table_A10.txt"
    
  # CREATE TABLE A11
  R CMD BATCH "--no-save --args TRUE" "R/float_code/Table_A11.R" "batch_output/out_Table_A11.txt"

  # ARGUMENTS FOR TABLE A12: MODELS_WITH_CONTROLS, ONLY_SUBJECTS_WHO_ANSWERED_CONTROL_QUESTIONS, ONLY_SUBJECTS_WHO_HAVE_WEIGHTS, USE_WEIGHTS, CREATE_SCREENER_TABLES
  R CMD BATCH "--no-save --args TRUE TRUE TRUE TRUE FALSE" "R/float_code/Table_2.R" "batch_output/out_Table_A12.txt"

  # TABLE A13 WAS CREATED ABOVE
  
  # TABLE A14 IS THE SECOND TABLE IN "Table_1.tex"
  

    
